<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <script src="bootstrap/js/jquery-3.5.1.min.js"></script>
    <script src="bootstrap/js/jquery.cookie.js"></script>
    <title>第一个HTML页面</title>

</head>
<body>
<div id="div1"><h2>使用 jQuery AJAX 修改文本内容</h2></div>
<button>获取其他内容</button>
<form name="f" action="http://client:123456@localhost:9001/small-service-auth/oauth/token" method="post">
    <br/>
    用户名:
    <input type="text" name="grant_type" placeholder="authorization_code" value="authorization_code"><br/>
    密码:
    <input type="text" name="code" placeholder="code"><br/>
    <input name="submit" type="submit" value="提交">
</form>
<script>
    $(() => {
        $("button").click(function () {
            let code = getUrlParam("code");
            console.log(code)
            $.ajax({
                url: "http://localhost:9001/small-service-flowable/application/get-token?code=" + code,
                contentType: "jsonp",
                type: 'GET',
                success: function (result) {
                    if (result.status === 200) {
                        $.cookie('name', result.data);
                    }
                }
            });
        });

        /*此方法为jquery 获取url路径参数的方法*/
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]);
            return null; //返回参数值
        }
    })
</script>


</body>
</html>
